package net.babypai.common;

import java.util.HashMap;

import net.babypai.utils.ImageOperation;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.util.DisplayMetrics;


public class Configure {
	public static int screenHeight = 0;
	public static int screenWidth = 0;
	public static float screenDensity = 0;

	public static Bitmap USER_FACE = null;
	public static Bitmap[] IIYAImages = null;
	public static String USER_NAME = null;
	public static String USER_ID = null;
	public static String USER_EMAIL = null;
	public static String USER_FACE_URL = null;
	public static String USER_AREA = null;
	public static double USER_LONGITUDE = 0;
	public static double USER_LATITUDE = 0;
	public static int USER_ISVIP = 0;
	
	public static HashMap<String, Bitmap> IIYAIMAGES;
	public static HashMap<String, Bitmap> FACEIMAGES;
	public static HashMap<String, Integer> PLAYERSTATUS;

	public static void inits(Activity context) {
		if (screenDensity == 0 || screenWidth == 0 || screenHeight == 0) {
			DisplayMetrics dm = new DisplayMetrics();
			context.getWindowManager().getDefaultDisplay().getMetrics(dm);
			Configure.screenDensity = dm.density;
			Configure.screenHeight = dm.heightPixels;
			Configure.screenWidth = dm.widthPixels;
		}
		if (USER_NAME == null || USER_EMAIL == null || USER_ID == null || USER_FACE_URL == null) {
			SharedPreferences configUser;
			configUser = context.getSharedPreferences(Constants.ACCOUNTS, 0);
			Configure.USER_ID = configUser.getInt(Constants.USER_ID, 0) + "";
			Configure.USER_NAME = configUser.getString(Constants.USER_NAME, null);
			Configure.USER_EMAIL = configUser.getString(Constants.USER_EMAIL, null);
			Configure.USER_FACE_URL = configUser.getString(Constants.USER_FACE_URL, null);
			Configure.USER_AREA = configUser.getString(Constants.USER_AREA, null);
			String longitude = configUser.getString(Constants.USER_LONGITUDE, null);
			Configure.USER_LONGITUDE = Double.parseDouble(longitude == null ? "0" : longitude);
			String latitude = configUser.getString(Constants.USER_LATITUDE, null);
			Configure.USER_LATITUDE = Double.parseDouble(latitude == null ? "0" : latitude);
			Configure.USER_ISVIP = configUser.getInt(Constants.USER_ISVIP, 0);
		}
		
		if (Configure.USER_FACE == null)
			Configure.USER_FACE = ImageOperation.getImageBitmap(context, Configure.USER_FACE_URL, Constants.SDCARDPIC);
	}

	public static int getScreenHeight(Activity context) {
		if (screenWidth == 0 || screenHeight == 0) {
			DisplayMetrics dm = new DisplayMetrics();
			context.getWindowManager().getDefaultDisplay().getMetrics(dm);
			Configure.screenDensity = dm.density;
			Configure.screenHeight = dm.heightPixels;
			Configure.screenWidth = dm.widthPixels;
		}
		return screenHeight;
	}

	public static int getScreenWidth(Activity context) {
		if (screenWidth == 0 || screenHeight == 0) {
			DisplayMetrics dm = new DisplayMetrics();
			context.getWindowManager().getDefaultDisplay().getMetrics(dm);
			Configure.screenDensity = dm.density;
			Configure.screenHeight = dm.heightPixels;
			Configure.screenWidth = dm.widthPixels;
		}
		return screenWidth;
	}
}
